<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Update index settings API | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'indices-update-settings.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/indices-update-settings.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/indices-update-settings.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/indices-update-settings.html" rel="nofollow" target="_blank">../en/indices-update-settings.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="indices.html">Index APIs</a></span>
»
<span class="breadcrumb-node">Update index settings API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="indices-aliases.html">« Update index alias API</a>
</span>
<span class="next">
<a href="index-lifecycle-management-api.html">Index lifecycle management API »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="indices-update-settings"></a>Update index settings API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/update-settings.asciidoc">edit</a>
</h2>
</div></div></div>

<p>Changes an <a class="xref" href="index-modules.html#index-modules-settings" title="Index Settings">index setting</a> in real time.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /twitter/_settings
{
    "index" : {
        "number_of_replicas" : 2
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1755.console"></div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="update-index-settings-api-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/update-settings.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">PUT /&lt;index&gt;/_settings</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="update-index-settings-api-path-params"></a>Path parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/update-settings.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">&lt;index&gt;</code>
</span>
</dt>
<dd>
<p>
(Optional, string) Comma-separated list or wildcard expression of index names
used to limit the request.
</p>
<p>To update a setting for all indices,
use <code class="literal">_all</code> or exclude this parameter.</p>
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="update-index-settings-api-query-params"></a>Query parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/update-settings.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">allow_no_indices</code>
</span>
</dt>
<dd>
<p>
(Optional, boolean) If <code class="literal">true</code>,
the request does <span class="strong strong"><strong>not</strong></span> return an error
if a wildcard expression
or <code class="literal">_all</code> value retrieves only missing or closed indices.
</p>
<p>This parameter also applies to <a class="xref" href="indices-aliases.html" title="Update index alias API">index aliases</a>
that point to a missing or closed index.</p>
<p>Defaults to <code class="literal">false</code>.</p>
</dd>
<dt>
<span class="term">
<code class="literal">expand_wildcards</code>
</span>
</dt>
<dd>
<p>(Optional, string) Controls what kind of indices that wildcard expressions can
expand to. Multiple values are accepted when separated by a comma, as in
<code class="literal">open,hidden</code>. Valid values are:</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">all</code>
</span>
</dt>
<dd>
Expand to open and closed indices, including <a class="xref" href="index-modules.html#index-hidden">hidden indices</a>.
</dd>
<dt>
<span class="term">
<code class="literal">open</code>
</span>
</dt>
<dd>
Expand only to open indices.
</dd>
<dt>
<span class="term">
<code class="literal">closed</code>
</span>
</dt>
<dd>
Expand only to closed indices.
</dd>
<dt>
<span class="term">
<code class="literal">hidden</code>
</span>
</dt>
<dd>
Expansion of wildcards will include <a class="xref" href="index-modules.html#index-hidden">hidden indices</a>.
Must be combined with <code class="literal">open</code>, <code class="literal">closed</code>, or both.
</dd>
<dt>
<span class="term">
<code class="literal">none</code>
</span>
</dt>
<dd>
Wildcard expressions are not accepted.
</dd>
</dl>
</div>
<p>Defaults to <code class="literal">open</code>.</p>
</dd>
<dt>
<span class="term">
<code class="literal">flat_settings</code>
</span>
</dt>
<dd>
(Optional, boolean) If <code class="literal">true</code>, returns settings in flat format. Defaults to
<code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">ignore_unavailable</code>
</span>
</dt>
<dd>
(Optional, boolean) If <code class="literal">true</code>, missing or closed indices are not included in the
response. Defaults to <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">preserve_existing</code>
</span>
</dt>
<dd>
(Optional, boolean) If <code class="literal">true</code>, existing index settings remain unchanged.
Defaults to <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">master_timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a connection to the master node. If no response is received before the timeout
expires, the request fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
<dt>
<span class="term">
<code class="literal">timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a response. If no response is received before the timeout expires, the request
fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="update-index-settings-api-request-body"></a>Request body<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/update-settings.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">settings</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="index-modules.html#index-modules-settings" title="Index Settings">index setting object</a>) Configuration
options for the index. See <a class="xref" href="index-modules.html#index-modules-settings" title="Index Settings">Index Settings</a>.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="update-index-settings-api-example"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/update-settings.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="reset-index-setting"></a>Reset an index setting<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/update-settings.asciidoc">edit</a>
</h4>
</div></div></div>
<p>To revert a setting to the default value, use <code class="literal">null</code>. For example:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /twitter/_settings
{
    "index" : {
        "refresh_interval" : null
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1756.console"></div>
<p>The list of per-index settings which can be updated dynamically on live
indices can be found in <a class="xref" href="index-modules.html" title="Index modules">Index modules</a>.
To preserve existing settings from being updated, the <code class="literal">preserve_existing</code>
request parameter can be set to <code class="literal">true</code>.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="bulk"></a>Bulk indexing usage<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/update-settings.asciidoc">edit</a>
</h4>
</div></div></div>
<p>For example, the update settings API can be used to dynamically change
the index from being more performant for bulk indexing, and then move it
to more real time indexing state. Before the bulk indexing is started,
use:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /twitter/_settings
{
    "index" : {
        "refresh_interval" : "-1"
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1757.console"></div>
<p>(Another optimization option is to start the index without any replicas,
and only later adding them, but that really depends on the use case).</p>
<p>Then, once bulk indexing is done, the settings can be updated (back to
the defaults for example):</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /twitter/_settings
{
    "index" : {
        "refresh_interval" : "1s"
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1758.console"></div>
<p>And, a force merge should be called:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /twitter/_forcemerge?max_num_segments=5</pre>
</div>
<div class="console_widget" data-snippet="snippets/1759.console"></div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="update-settings-analysis"></a>Update index analysis<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/update-settings.asciidoc">edit</a>
</h4>
</div></div></div>
<p>You can only define new analyzers on closed indices.</p>
<p>To add an analyzer,
you must close the index,
define the analyzer,
and reopen the index.
For example,
the following commands add the <code class="literal">content</code> analyzer to <code class="literal">myindex</code>:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /twitter/_close

PUT /twitter/_settings
{
  "analysis" : {
    "analyzer":{
      "content":{
        "type":"custom",
        "tokenizer":"whitespace"
      }
    }
  }
}

POST /twitter/_open</pre>
</div>
<div class="console_widget" data-snippet="snippets/1760.console"></div>
</div>

</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="indices-aliases.html">« Update index alias API</a>
</span>
<span class="next">
<a href="index-lifecycle-management-api.html">Index lifecycle management API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>